/**
 * Definition for a binary tree node.
 * public class TreeNode {
 *     int val;
 *     TreeNode left;
 *     TreeNode right;
 *     TreeNode(int x) { val = x; }
 * }
 */
class Solution {
    List<Integer> list;
    public int kthLargest(TreeNode root, int k) {
        list = new LinkedList<>();
        if(root == null) {
            return 0;
        }
        dfc(root);
        Object[] objects = list.toArray();
        Arrays.sort(objects);
        int length = objects.length;
        return (int)objects[length - k];
    }

    public void dfc(TreeNode root) {
        if(root == null) {
            return;
        }
        list.add(root.val);
        dfc(root.left);
        dfc(root.right);
    }
}